﻿<sdk:Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
    x:Class="MoneyBook.Views.CreateUserView" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    xmlns:li="clr-namespace:MoneyBook.Interactivity"
    xmlns:lv="clr-namespace:MoneyBook.Views"
    x:Name="Self"
    d:DesignWidth="640" d:DesignHeight="480">
    <sdk:Page.Resources>
        <Style TargetType="TextBox" BasedOn="{StaticResource InputControlStyle}">
            <Setter Property="Height" Value="28" />
            <Setter Property="Width" Value="160" />
        </Style>
        <Style TargetType="PasswordBox" BasedOn="{StaticResource InputControlStyle}">
            <Setter Property="Height" Value="28" />
            <Setter Property="Width" Value="160" />
        </Style>
    </sdk:Page.Resources>
    <sdk:Page.DataContext>
        <lv:CreateUserViewModel />
    </sdk:Page.DataContext>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        
        <sdk:ValidationSummary Grid.Row="0" Width="400" HorizontalAlignment="Left" />
        
        <Grid Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top">
            <i:Interaction.Behaviors>
                <li:DefaultButtonBehavior TargetButton="{Binding ElementName=CreateUserButton}" />
            </i:Interaction.Behaviors>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <sdk:Label Target="{Binding ElementName=MemberNameTextBox}" />
            <TextBox Grid.Column="1" x:Name="MemberNameTextBox" 
                     Text="{Binding MemberName, Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}" />

            <sdk:Label Grid.Row="1" Target="{Binding ElementName=DisplayNameTextBox}" />
            <TextBox  Grid.Row="1" Grid.Column="1" x:Name="DisplayNameTextBox" 
                     Text="{Binding DisplayName, Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}" />

            <sdk:Label Grid.Row="2" Target="{Binding ElementName=PasswordTextBox}" />
            <PasswordBox Grid.Row="2" Grid.Column="1" x:Name="PasswordTextBox" 
                         Password="{Binding Password, Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}" />

            <sdk:Label Grid.Row="3" Target="{Binding ElementName=RePasswordTextBox}" />
            <PasswordBox Grid.Row="3" Grid.Column="1" x:Name="RePasswordTextBox" 
                         Password="{Binding RePassword, Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}" />

            <Button Content="{Binding CreateUserButton,Source={StaticResource Strings}}" 
                    Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Right" 
                    x:Name="CreateUserButton">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:Interaction.Behaviors>
                            <ei:ConditionBehavior>
                                <ei:ConditionalExpression>
                                    <ei:ComparisonCondition LeftOperand="{Binding DataContext.HasBindingValidationErrors, ElementName=Self}"
                                                            RightOperand="false" />
                                </ei:ConditionalExpression>
                            </ei:ConditionBehavior>
                        </i:Interaction.Behaviors>

                        <li:InvokeMethodAction TargetObject="{Binding DataContext, ElementName=Self}" MethodName="CreateUser"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>

        </Grid>
    </Grid>
</sdk:Page>